package com.ruoyi.project.lesson.lessoncatalog.service.impl;

import com.ruoyi.common.utils.text.Convert;
import com.ruoyi.framework.aspectj.lang.annotation.DataSource;
import com.ruoyi.framework.aspectj.lang.enums.DataSourceType;
import com.ruoyi.project.common.service.ICommonService;
import com.ruoyi.project.lesson.lessoncatalog.domain.LessonCatalog;
import com.ruoyi.project.lesson.lessoncatalog.mapper.LessonCatalogMapper;
import com.ruoyi.project.lesson.lessoncatalog.service.ILessonCatalogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 课程目录Service业务层处理
 *
 * @author shixiangwen
 * @date 2021-05-10
 */
@Service
@DataSource(DataSourceType.KKFORMULA)
public class LessonCatalogServiceImpl implements ILessonCatalogService {

    @Autowired
    private LessonCatalogMapper lessonCatalogMapper;

    @Autowired
    private ICommonService commonService;


    /**
     * 查询课程目录
     *
     * @param id 课程目录ID
     * @return 课程目录
     */
    @Override
    public LessonCatalog selectLessonCatalogById(Long id) {
        return lessonCatalogMapper.selectLessonCatalogById(id);
    }

    /**
     * 查询课程目录列表
     *
     * @param lessonCatalog 课程目录
     * @return 课程目录
     */
    @Override
    public List<LessonCatalog> selectLessonCatalogList(LessonCatalog lessonCatalog) {
        return lessonCatalogMapper.selectLessonCatalogList(lessonCatalog);
    }

    /**
     * 新增课程目录
     *
     * @param lessonCatalog 课程目录
     * @return 结果
     */
    @Override
    public int insertLessonCatalog(LessonCatalog lessonCatalog) {
        return lessonCatalogMapper.insertLessonCatalog(lessonCatalog);
    }

    /**
     * 修改课程目录
     *
     * @param lessonCatalog 课程目录
     * @return 结果
     */
    @Override
    public int updateLessonCatalog(LessonCatalog lessonCatalog) {
        return lessonCatalogMapper.updateLessonCatalog(lessonCatalog);
    }

    /**
     * 删除课程目录对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteLessonCatalogByIds(String ids) {
        return lessonCatalogMapper.deleteLessonCatalogByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除课程目录信息
     *
     * @param id 课程目录ID
     * @return 结果
     */
    @Override
    public int deleteLessonCatalogById(Long id) {
        return lessonCatalogMapper.deleteLessonCatalogById(id);
    }

    @Override
    public int getMaxSort(Long lessonId) {
        return commonService.selectTableColumnMaxValue("lesson_catalog", "sort", " lesson_id = " + lessonId) + 1;
    }
}
